package com.ruoyi.source.service.impl;

import java.util.*;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.source.api.domain.SrcCheckRecord;
import com.ruoyi.source.api.domain.SrcLogistics;
import com.ruoyi.source.mapper.SrcCheckRecordMapper;

import com.ruoyi.source.mapper.SrcLogisticsMapper;
import com.ruoyi.source.service.CheckRecordService;
import com.ruoyi.system.api.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 货物质检Service业务层处理
 *
 * @author ruoyi
 * @date 2024-07-23
 */
@Service
public class SrcCheckRecordServiceImpl extends ServiceImpl<SrcCheckRecordMapper,SrcCheckRecord> implements CheckRecordService {

    /**
     * 查询货物质检列表
     *
     * @param srcCheckRecord 货物质检
     * @return 货物质检
     */
    @Override
    public List<SrcCheckRecord> selectSrcCheckRecordList(SrcCheckRecord srcCheckRecord) {
        List<SrcCheckRecord> srcCheckRecords = baseMapper.selectSrcCheckRecordList(srcCheckRecord);
//        List<SrcCheckRecord> collect = srcCheckRecords.stream().filter(src -> src.getInspectors().equals(SecurityUtils.getUserId())).collect(Collectors.toList());
        return srcCheckRecords;
    }

    /**
     * 新增货物质检
     *
     * @param srcCheckRecord 货物质检
     * @return 结果
     */
    @Override
    public int insertSrcCheckRecord(SrcCheckRecord srcCheckRecord) {
        srcCheckRecord.setCreateTime(DateUtils.getNowDate());
        srcCheckRecord.setCreateBy(SecurityUtils.getUsername());
        return baseMapper.insert(srcCheckRecord);
    }

    /**
     * 修改货物质检
     *
     * @param srcCheckRecord 货物质检
     * @return 结果
     */
    @Override
    public int updateSrcCheckRecord(SrcCheckRecord srcCheckRecord) {
        Long userId=SecurityUtils.getUserId();
        Long deptId=baseMapper.checkDeptId(userId);
        if(deptId==205){
            srcCheckRecord.setInspectors(SecurityUtils.getUserId());
            srcCheckRecord.setUpdateBy(SecurityUtils.getUsername());
            srcCheckRecord.setUpdateTime(DateUtils.getNowDate());
            srcCheckRecord.setCheckTime(new Date());
            return baseMapper.updateById(srcCheckRecord);
        }
        return 0;
    }

    @Override
    public List<Map<String, Object>> selectCheckRecords() {
        return baseMapper.selectCheckRecords();
    }


    @Override
    public List<SrcCheckRecord> selectCheckRecord() {
        return baseMapper.selectCheckRecord();
    }
}
